"""
ASGI config for chat_backend project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""
import sys
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chat_backend.settings')

from .wbesocket import websocket_application
from django.core.asgi import get_asgi_application

# 实例对象()  ->  __call__ 方法
application = get_asgi_application()


async def chat_application(scope, receive, send):
    print('scope: ', scope['type'])
    if scope['type'] == 'http':
        await application(scope, receive, send)
    elif scope['type'] == 'websocket':
        await websocket_application(scope, receive, send)
    else:
        raise Exception('unknow scope type, ' + scope['type'])

